﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;
using System.Data.SqlClient;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 信息类别数据类
    /// </summary>
    public class DocCls
    {        
        /// <summary>
        /// 特定栏目是否有特定的权限
        /// <creator>wangl</creator>
        /// <date>2013-08-06</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="empNo">员工编号</param>
        /// <param name="deptNo">部门编号</param>
        /// <param name="authority">权限</param>
        /// <param name="docClsNo">信息类别编号</param>
        /// <returns></returns>
        public bool ExistsAuthorityDocClsNo(string entityNo, string empNo, string deptNo, string authority, string docClsNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 Fdocclscd,fpredocclscd,fdocclsprop,fdocclsname,fisauthority from dbo.fn_GetDocClsByAuthority(");
            strSql.Append(" @FEntityNo,@FDeptNo,@FEmplNo,@FAuthorityType)");
            strSql.Append(" WHERE FDocClsCd=@FDocClsCd");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAuthorityType", SqlDbType.NVarChar,10),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
                    new SqlParameter("@FDeptNo",SqlDbType.NVarChar,12),
                     new SqlParameter("@FDocClsCd",SqlDbType.VarChar,25)                    
                                        };
            parameters[0].Value = entityNo;
            parameters[1].Value = authority;
            parameters[2].Value = empNo;
            parameters[3].Value = deptNo;
            parameters[4].Value = docClsNo;
            if (DbHelperSQL.Exists(strSql.ToString(), parameters))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 得到一个对象
        /// <creator>wangl</creator>
        /// <date>2013-07-23</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">信息类别编号</param>
        /// <returns></returns>
        public Model.DocCls GetModel(string entityNo, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT FEntityNo,FDocClsCd,FPreDocClsCd,FDocClsProp,FDocClsName,FIsUse,FUseSubTitle,FIsPicNews,FPicHeight,FPicWidth,FIsPicWaterMark,FWaterMarkCls,FIsHomePageShowLimit,FHomePageShowDays,FEditMode,FDefaultEditMode,FIsNeedAudit,FIsShowHomePageCtrl,FDefaultShowValue,FIsPublicTitle,FIsCtrlLookAuthority,FIsReferenceNo,FIsNotice,FIsRecObject,FIsMeeting,FWaterMarkPos,FIsIndex,FLeftRightMargin,FTopBottomMargin,FLogoOldFileName,FLogoNewFileName,FLogoImage,FDocClsHomepage,FCreateDate,FIsImport,FSeq,FIsPubJCMS,FJCMSColID,FClsTemplID,FTemplTopPicPath,FIsExamine,FIsManuscript,FIsSpecialTopic,FIsVote,FLookAuthorityMode FROM t_docCls ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocClsCd=@FDocClsCd");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,50)
                                        };
            parameters[0].Value = entityNo;
            parameters[1].Value = docClsCd;

            Model.DocCls model = new Model.DocCls();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获取下一级目录的个数
        /// <creator>wangl</creator>
        /// <date>2013-07-23</date>
        /// </summary>
        /// <param name="docClsCd">信息栏目编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>下级目录数量</returns>
        public int GetChildeCount(string docClsCd, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select count(*) from t_docCls ");
            strSql.Append(" where FPreDocClsCd=@FPreDocClsCd and FEntityNo=@FEntityNo and  FIsUse='1' ");

            SqlParameter[] parameters = {
					new SqlParameter("@FPreDocClsCd", SqlDbType.NVarChar,12),
                    new SqlParameter("@FEntityNo",SqlDbType.NVarChar,12)};

            parameters[0].Value = docClsCd;
            parameters[1].Value = entityNo;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (null != obj)
            {
                return int.Parse(obj.ToString());
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-07-22</date> 
        /// </summary>
        /// <param name="row">数据行</param>
        /// <returns>信息类别实体</returns>
        public ElingOA6_DSJCJ.Model.DocCls DataRowToModel(DataRow row)
        {
            ElingOA6_DSJCJ.Model.DocCls model = new ElingOA6_DSJCJ.Model.DocCls();
            if (row != null)
            {
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FDocClsCd"] != null)
                {
                    model.FDocClsCd = row["FDocClsCd"].ToString();
                }
                if (row["FPreDocClsCd"] != null)
                {
                    model.FPreDocClsCd = row["FPreDocClsCd"].ToString();
                }
                if (row["FDocClsProp"] != null)
                {
                    model.FDocClsProp = row["FDocClsProp"].ToString();
                }
                if (row["FDocClsName"] != null)
                {
                    model.FDocClsName = row["FDocClsName"].ToString();
                }
                if (row["FIsUse"] != null && row["FIsUse"].ToString() != "")
                {
                    model.FIsUse = int.Parse(row["FIsUse"].ToString());
                }
                if (row["FUseSubTitle"] != null && row["FUseSubTitle"].ToString() != "")
                {
                    model.FUseSubTitle = int.Parse(row["FUseSubTitle"].ToString());
                }
                if (row["FIsPicNews"] != null && row["FIsPicNews"].ToString() != "")
                {
                    model.FIsPicNews = decimal.Parse(row["FIsPicNews"].ToString());
                }
                if (row["FPicHeight"] != null && row["FPicHeight"].ToString() != "")
                {
                    model.FPicHeight = int.Parse(row["FPicHeight"].ToString());
                }
                if (row["FPicWidth"] != null && row["FPicWidth"].ToString() != "")
                {
                    model.FPicWidth = int.Parse(row["FPicWidth"].ToString());
                }
                if (row["FIsPicWaterMark"] != null && row["FIsPicWaterMark"].ToString() != "")
                {
                    model.FIsPicWaterMark = decimal.Parse(row["FIsPicWaterMark"].ToString());
                }
                if (row["FWaterMarkCls"] != null)
                {
                    model.FWaterMarkCls = row["FWaterMarkCls"].ToString();
                }
                if (row["FIsHomePageShowLimit"] != null)
                {
                    model.FIsHomePageShowLimit = row["FIsHomePageShowLimit"].ToString();
                }
                if (row["FHomePageShowDays"] != null && row["FHomePageShowDays"].ToString() != "")
                {
                    model.FHomePageShowDays = int.Parse(row["FHomePageShowDays"].ToString());
                }
                if (row["FEditMode"] != null)
                {
                    model.FEditMode = row["FEditMode"].ToString();
                }
                if (row["FDefaultEditMode"] != null)
                {
                    model.FDefaultEditMode = row["FDefaultEditMode"].ToString();
                }
                if (row["FIsNeedAudit"] != null)
                {
                    model.FIsNeedAudit = row["FIsNeedAudit"].ToString();
                }
                if (row["FIsShowHomePageCtrl"] != null)
                {
                    model.FIsShowHomePageCtrl = row["FIsShowHomePageCtrl"].ToString();
                }
                if (row["FDefaultShowValue"] != null)
                {
                    model.FDefaultShowValue = row["FDefaultShowValue"].ToString();
                }
                if (row["FIsPublicTitle"] != null)
                {
                    model.FIsPublicTitle = row["FIsPublicTitle"].ToString();
                }
                if (row["FIsCtrlLookAuthority"] != null)
                {
                    model.FIsCtrlLookAuthority = row["FIsCtrlLookAuthority"].ToString();
                }
                if (row["FIsReferenceNo"] != null)
                {
                    model.FIsReferenceNo = row["FIsReferenceNo"].ToString();
                }
                if (row["FIsNotice"] != null)
                {
                    model.FIsNotice = row["FIsNotice"].ToString();
                }
                if (row["FIsRecObject"] != null)
                {
                    model.FIsRecObject = row["FIsRecObject"].ToString();
                }
                if (row["FIsMeeting"] != null)
                {
                    model.FIsMeeting = row["FIsMeeting"].ToString();
                }
                if (row["FWaterMarkPos"] != null)
                {
                    model.FWaterMarkPos = row["FWaterMarkPos"].ToString();
                }
                if (row["FIsIndex"] != null)
                {
                    model.FIsIndex = row["FIsIndex"].ToString();
                }
                if (row["FLeftRightMargin"] != null && row["FLeftRightMargin"].ToString() != "")
                {
                    model.FLeftRightMargin = int.Parse(row["FLeftRightMargin"].ToString());
                }
                if (row["FTopBottomMargin"] != null && row["FTopBottomMargin"].ToString() != "")
                {
                    model.FTopBottomMargin = int.Parse(row["FTopBottomMargin"].ToString());
                }
                if (row["FLogoOldFileName"] != null)
                {
                    model.FLogoOldFileName = row["FLogoOldFileName"].ToString();
                }
                if (row["FLogoNewFileName"] != null)
                {
                    model.FLogoNewFileName = row["FLogoNewFileName"].ToString();
                }
                if (row["FLogoImage"] != null && row["FLogoImage"].ToString() != "")
                {
                    model.FLogoImage = (byte[])row["FLogoImage"];
                }
                if (row["FDocClsHomepage"] != null)
                {
                    model.FDocClsHomepage = row["FDocClsHomepage"].ToString();
                }
                if (row["FCreateDate"] != null && row["FCreateDate"].ToString() != "")
                {
                    model.FCreateDate = DateTime.Parse(row["FCreateDate"].ToString());
                }
                if (row["FIsImport"] != null)
                {
                    model.FIsImport = row["FIsImport"].ToString();
                }
                if (row["FSeq"] != null && row["FSeq"].ToString() != "")
                {
                    model.FSeq = int.Parse(row["FSeq"].ToString());
                }
                if (row["FIsPubJCMS"] != null)
                {
                    model.FIsPubJCMS = row["FIsPubJCMS"].ToString();
                }
                if (row["FJCMSColID"] != null && row["FJCMSColID"].ToString() != "")
                {
                    model.FJCMSColID = int.Parse(row["FJCMSColID"].ToString());
                }
                if (row["FClsTemplID"] != null && row["FClsTemplID"].ToString() != "")
                {
                    model.FClsTemplID = decimal.Parse(row["FClsTemplID"].ToString());
                }
                if (row["FTemplTopPicPath"] != null)
                {
                    model.FTemplTopPicPath = row["FTemplTopPicPath"].ToString();
                }
                if (row["FIsExamine"] != null)
                {
                    model.FIsExamine = row["FIsExamine"].ToString();
                }
                if (row["FIsManuscript"] != null)
                {
                    model.FIsManuscript = row["FIsManuscript"].ToString();
                }
                if (row.Table.Columns.Contains("FIsSpecialTopic"))
                {
                    if (row["FIsSpecialTopic"] != null)
                    {
                        model.FIsSpecialTopic = row["FIsSpecialTopic"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FIsVote"))
                {
                    if (row["FIsVote"] != null)
                    {
                        model.FIsVote = row["FIsVote"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FLookAuthorityMode"))
                {
                    if (row["FLookAuthorityMode"] != null)
                    {
                        model.FLookAuthorityMode = row["FLookAuthorityMode"].ToString();
                    }
                }
            }
            return model;
        }
        
        /// <summary>
        /// 是否存在该记录
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">信息类别</param>
        /// <returns>true-存在 false-不存在</returns>
        public bool Exists(string entityNo, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_docCls");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocClsCd=@FDocClsCd and FIsUse=1");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,50)};
            parameters[0].Value = entityNo;
            parameters[1].Value = docClsCd;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 获得数据列表,根据公司编号和上级编号
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        public DataSet GetListByEntityNoAndPreDocClsNo(string entityNo, string preDocClsNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * FROM t_docCls");
            strSql.Append(" where FEntityNo=@FEntityNo and FIsUse=1");
            int t = 0;
            if (preDocClsNo != "")
            {
                strSql.Append(" and FPreDocClsCd=@FPreDocClsCd");
                t = 1;
            }
            else
            {
                strSql.Append(" and FPreDocClsCd is null");
            }

            strSql.Append(" order by FSeq,FDocClsCd");

            if (t == 1)
            {
                SqlParameter[] parameters = { 
                     new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                     new SqlParameter("@FPreDocClsCd", SqlDbType.VarChar,50)};
                parameters[0].Value = entityNo;
                parameters[1].Value = preDocClsNo;

                return DbHelperSQL.Query(strSql.ToString(), parameters);
            }
            else
            {

                SqlParameter[] parameters = { 
                 new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
                parameters[0].Value = entityNo;

                return DbHelperSQL.Query(strSql.ToString(), parameters);
            }
        }
        
        /// <summary>
        /// 根据编号，获取其父类编号和其组成的路径 01/02/03
        /// <creator>wangl</creator>
        /// <date>2013-08-13</date> 
        /// </summary>
        /// <param name="docClsCd">信息类别编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public string GetDocClsCdS(string docClsCd, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select dbo.fn_getDocClsNoS(@FDocClsCd,@FEntityNo)");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25)};
            parameters[0].Value = entityNo;
            parameters[1].Value = docClsCd;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                if (sdr.Read())
                {
                    return sdr[0].ToString();
                }
            }
            return docClsCd;
        }
        /// <summary>
        /// 获取信息类别名称路径名
        /// <creator>wangl</creator>
        /// <date>2013-08-14</date> 
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">信息类别编号</param>
        /// <returns>名称路径名</returns>
        public string GetDocClsPathNames(string entityNo, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select dbo.fn_getDocClsNames(@FDocClsCd,@FEntityNo)");
            SqlParameter[] parameters = {
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,50),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = docClsCd;
            parameters[1].Value = entityNo;
            using (SqlDataReader sda = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                if (sda.Read())
                {
                    return sda[0].ToString();
                }
            }

            return "";
        }
        /// <summary>
        /// 获取所有的有效的子栏目
        /// <creator>wangl</creator>
        /// <date>2013-09-09</date>
        /// </summary>
        /// <param name="FEntityNo"></param>
        /// <returns></returns>
        public DataSet GetAllSubDocCls(string docClsCd, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select FEntityNo,FDocClsCd,FDocClsName,FDocClsProp,FIsUse,FLogoNewFileName,FLogoOldFileName,FDocClsHomepage,FIsLast,LEVEL from fn_GetSubDocCls(@FDocClsCd,@FEntityNo)");
            strSql.Append(" where FIsUse='1'   ORDER BY  FSeq, FDocClsCd");

            SqlParameter[] parameters = {
					new SqlParameter("@FDocClsCd", SqlDbType.NVarChar,15),
                    new SqlParameter("@FEntityNo",SqlDbType.NVarChar,15)};

            parameters[0].Value = docClsCd;
            parameters[1].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 获取下一级的有效的子栏目
        /// <creator>wangl</creator>
        /// <date>2014-02-27</date>
        /// </summary>
        /// <param name="FDocClsCd"></param>
        /// <param name="FEntityNo"></param>
        /// <returns></returns>
        public DataSet GetSubDocCls(string docClsCd, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select FEntityNo,FDocClsCd,FDocClsName from t_docCls ");
            strSql.Append(" where FPreDocClsCd=@FDocClsCd AND FEntityNo=@FEntityNo AND FIsUse='1' ");
            strSql.Append("ORDER BY  FSeq, FDocClsCd");

            SqlParameter[] parameters = {
					new SqlParameter("@FDocClsCd", SqlDbType.NVarChar,15),
                    new SqlParameter("@FEntityNo",SqlDbType.NVarChar,15)};

            parameters[0].Value = docClsCd;
            parameters[1].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 获取专题专栏（已启用）
        /// <creator>wangl</creator>
        /// <date>2013-10-30</date>
        /// </summary>
        /// <param name="preDocClsID"></param>
        /// <param name="entityNo"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public DataSet GetIdAndLogUrl(string preDocClsID, string entityNo, int top = 0)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select");
            if (top > 0)
            {
                strSql.Append(" top ");
                strSql.Append(top);
            }
            strSql.Append(" FDocClsCd,FLogoNewFileName from t_docCls");
            strSql.Append(" where FIsUse='1' and  FPreDocClsCd=@FPreDocClsCd and FEntityNo=@FEntityNo order by FSeq, FDocClsCd");

            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FPreDocClsCd", SqlDbType.VarChar,25)	};
            parameters[0].Value = entityNo;
            parameters[1].Value = preDocClsID;

            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }
        /// <summary>
        /// 获取专题专栏(包含启用未启用)
        /// <creator>wangl</creator>
        /// <date>2013-10-30</date>
        /// </summary>
        /// <param name="preDocClsID"></param>
        /// <param name="entityNo"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public DataSet GetIdAndLogUrlAll(string preDocClsID, string entityNo, int top = 0)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select");
            if (top > 0)
            {
                strSql.Append(" top ");
                strSql.Append(top);
            }
            strSql.Append(" FDocClsCd,FLogoNewFileName from t_docCls");
            strSql.Append(" where FPreDocClsCd=@FPreDocClsCd and FEntityNo=@FEntityNo order by FSeq, FDocClsCd");

            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FPreDocClsCd", SqlDbType.VarChar,25)	};
            parameters[0].Value = entityNo;
            parameters[1].Value = preDocClsID;

            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }

        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEntityNo,FDocClsCd,FPreDocClsCd,FDocClsProp,FDocClsName,FIsUse,FUseSubTitle,FIsPicNews,FPicHeight,FPicWidth,FIsPicWaterMark,FWaterMarkCls,FIsHomePageShowLimit,FHomePageShowDays,FEditMode,FDefaultEditMode,FIsNeedAudit,FIsShowHomePageCtrl,FDefaultShowValue,FIsPublicTitle,FIsCtrlLookAuthority,FIsReferenceNo,FIsNotice,FIsRecObject,FIsMeeting,FWaterMarkPos,FIsIndex,FLeftRightMargin,FTopBottomMargin,FLogoOldFileName,FLogoNewFileName,FLogoImage,FDocClsHomepage,FCreateDate,FIsImport,FSeq,FIsPubJCMS,FJCMSColID,FClsTemplID,FTemplTopPicPath,FIsExamine,FIsManuscript,FIsSpecialTopic,FIsVote,FDocSearchClsCd,FLookAuthorityMode ");
            strSql.Append(" FROM t_docCls ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获取目录下第一级目录
        /// </summary>
        /// <param name="preDocClsCd"></param>
        /// <param name="entityNO"></param>
        /// <returns></returns>
        public DataSet GetSubDocClsOne(string preDocClsCd, string entityNO)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from t_docCls where FPreDocClsCd=@FPreDocClsCd and FEntityNo=@FEntityNo and FIsUse=1 order by FSeq,FDocClsCd");

            SqlParameter[] parameters = {
                new SqlParameter("@FPreDocClsCd",SqlDbType.VarChar,25),
                new SqlParameter("@FEntityNo",SqlDbType.VarChar,15)};

            parameters[0].Value = preDocClsCd;
            parameters[1].Value = entityNO;

            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }


        /// <summary>
        /// 根据用户权限获取树目录
        /// <creator>wangl</creator>
        /// <date>2013-08-05</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="empNo">员工编号</param>
        /// <param name="deptNo">部门编号</param>
        /// <param name="authority">权限</param>
        /// <returns>不使用</returns>
        //public DataSet GetListByAuthority(string entityNo, string empNo, string deptNo, string authority)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select Fdocclscd,fpredocclscd,fdocclsprop,fdocclsname,fisauthority from dbo.fn_GetDocClsByAuthority(");
        //    strSql.Append(" @FEntityNo,@FDeptNo,@FEmplNo,@FAuthorityType)");

        //    SqlParameter[] parameters = {
        //            new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
        //            new SqlParameter("@FAuthorityType", SqlDbType.NVarChar,10),
        //            new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
        //            new SqlParameter("@FDeptNo",SqlDbType.NVarChar,12)};
        //    parameters[0].Value = entityNo;
        //    parameters[1].Value = authority;
        //    parameters[2].Value = empNo;
        //    parameters[3].Value = deptNo;

        //    return DbHelperSQL.Query(strSql.ToString(), parameters);
        //}
        public DataSet GetListByAuthority(string entityNo, string empNo, string deptNo, string authority, decimal docId, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Fdocclscd,fpredocclscd,fdocclsprop,fdocclsname,fisauthority from dbo.fn_GetDocClsByAuthority(");
            strSql.Append(" @FEntityNo,@FDeptNo,@FEmplNo,@FAuthorityType)");
            strSql.Append(" WHERE FDocClsCd!=@FDocClsCd ");
            strSql.Append(" AND FDocClsCd NOT IN (SELECT FDocClsCd FROM dbo.t_DocRefImp WHERE FDocId=@FDocId AND FEntityNo=@FEntityNo) ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAuthorityType", SqlDbType.NVarChar,10),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
                    new SqlParameter("@FDeptNo",SqlDbType.NVarChar,12),
                    new SqlParameter("@FDocClsCd",SqlDbType.VarChar,25),
                    new SqlParameter("@FDocId",SqlDbType.Decimal)
                                        };
            parameters[0].Value = entityNo;
            parameters[1].Value = authority;
            parameters[2].Value = empNo;
            parameters[3].Value = deptNo;
            parameters[4].Value = docClsCd;
            parameters[5].Value = docId;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 获取分局的信息类别
        /// <creator>sunlj</creator>
        /// <date>2013-09-07</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="deptNo">部门编号</param>
        /// <returns></returns>
        public DataSet GetLZZCDocCls(string entityNo, string clsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT  DISTINCT FDocClsCd,FPreDocClsCd,FDocClsName,ClsLevel,FSeq FROM (");
            strSql.Append("select DISTINCT FDocClsCd,FPreDocClsCd,FDocClsName,ClsLevel,FSeq ");
            strSql.Append(" FROM fn_GetLZZCDocCls(@FEntityNo,@DocClsCd) ");
            strSql.Append(" UNION ALL ");
            strSql.Append("select DISTINCT FDocClsCd,FPreDocClsCd,FDocClsName,ClsLevel,FSeq ");
            strSql.Append(" FROM fn_GetLZZCDocCls_Pre(@FEntityNo,@DocClsCd) ");

            strSql.Append(") a");
            strSql.Append(" ORDER BY ClsLevel ,fseq");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@DocClsCd",SqlDbType.NVarChar,12)};
            parameters[0].Value = entityNo;
            parameters[1].Value = clsCd;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
    }
}
